/**
 *
 *  Copyright (c) 2011, AstroDAbis
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without modification,
 *  are permitted provided that the following conditions are met:
 *
 *      * Redistributions of source code must retain the above copyright notice,
 *        this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above copyright notice,
 *        this list of conditions and the following disclaimer in the documentation
 *        and/or other materials provided with the distribution.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 *  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
package org.jiscinvolve.astrodabis.galium.ogsadai.activity.client;

import uk.org.ogsadai.activity.ActivityName;
import uk.org.ogsadai.client.toolkit.Activity;
import uk.org.ogsadai.client.toolkit.ActivityOutput;
import uk.org.ogsadai.client.toolkit.SingleActivityOutput;
import uk.org.ogsadai.client.toolkit.activity.ActivityInput;
import uk.org.ogsadai.client.toolkit.activity.BaseActivity;
import uk.org.ogsadai.client.toolkit.activity.SimpleActivityInput;
import uk.org.ogsadai.client.toolkit.activity.SimpleActivityOutput;
import uk.org.ogsadai.client.toolkit.exception.ActivityIOIllegalStateException;
import uk.org.ogsadai.data.StringData;

/**
 * Client toolkit proxy for:
 * <code>
 * org.jiscinvolve.astrodabis.galium.ogsadai.activity.server.ResultProcessingActivity
 * </code>
 *
 * Based on the example
 * <a href='http://ogsa-dai.sourceforge.net/documentation/ogsadai4.1/ogsadai4.1-axis/ActivityExampleTupleProcessing.html'>TupleProcessingActivity</a> 
 * from the OGSA-DAI documentation.
 * 
 *
 */
public class ResultProcessing
    extends BaseActivity implements Activity
    {

    /**
     * Default activity name.
     *
     */
    public final static ActivityName DEFAULT_ACTIVITY_NAME = 
        new ActivityName(
            "astrodabis.ResultProcessing"
            );

    /**
     * Activity input - the job identifier.
     *
     */
    private ActivityInput astroQueryIdInput;

    /**
     * Activity input - tuples.
     *
     */
    private ActivityInput mTuplesInput;

    /**
     * Activity output - result.
     *
     */
    private ActivityOutput mResultOutput;

    /**
     * Public constructor.
     *
     */
    public ResultProcessing()
        {
        super(DEFAULT_ACTIVITY_NAME);
        astroQueryIdInput = new SimpleActivityInput(
            "query"
            );
        mTuplesInput = new SimpleActivityInput(
            "tuples"
            );
        mResultOutput = new SimpleActivityOutput(
            "result"
            );
        }
    
    /**
     * Adds the job identifier input.
     * 
     * @param value
     *     The job identifier.
     */
    public void addJobId(String value)
        {
        astroQueryIdInput.add(
            new StringData(
                value
                )
            );
        }
   
    /**
     * Connects the job identifier input to an output.
     * 
     * @param output 
     *     Output to connect to.
     */
    public void connectJobIdInput(SingleActivityOutput output)
        {
        astroQueryIdInput.connect(
            output
            );
        }

    /**
     * Connects the tuples input to the given output.
     * 
     * @param output 
     *     Output to connect to.
     */
    public void connectTuplesInput(SingleActivityOutput output)
        {
        mTuplesInput.connect(
            output
            );
        }
    
    /**
     * Gets the result output so that it can be connected to the input
     * of other activities.
     * 
     * @return the activity output.
     */
    public SingleActivityOutput getResultOutput()
        {
        return mResultOutput.getSingleActivityOutputs()[0];
        }
    
    /**
     * Gets the activity inputs.
     *
     */
    protected ActivityInput[] getInputs()
        {
        return new ActivityInput[]{
            astroQueryIdInput,
            mTuplesInput
            };
        }

    /**
     * Gets the activity outputs.
     *
     */
    protected ActivityOutput[] getOutputs()
        {
        return new ActivityOutput[]{
            mResultOutput
            };
        }

    /**
     * Validates the data of the inputs and outputs.
     *
     */
    protected void validateIOState()
    throws ActivityIOIllegalStateException
        {
        // No further validation to do
        }
    }

